package com.ewanghuiju.app.ui.my.activity;

import android.view.View;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.bigkoo.pickerview.builder.OptionsPickerBuilder;
import com.bigkoo.pickerview.builder.TimePickerBuilder;
import com.bigkoo.pickerview.listener.CustomListener;
import com.bigkoo.pickerview.listener.OnOptionsSelectListener;
import com.bigkoo.pickerview.listener.OnTimeSelectListener;
import com.bigkoo.pickerview.view.OptionsPickerView;
import com.bigkoo.pickerview.view.TimePickerView;
import com.ewanghuiju.app.R;
import com.ewanghuiju.app.app.Constants;
import com.ewanghuiju.app.base.SimpleActivity;
import com.ewanghuiju.app.util.StartActivityUtil;
import com.ewanghuiju.app.util.TimeUtils;
import com.ewanghuiju.app.util.ToastUtil;
import com.ewanghuiju.app.util.nodoubleclick.AntiShake;
import com.gyf.immersionbar.ImmersionBar;

import java.util.ArrayList;
import java.util.Date;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * @author sj  qq:751943509
 * @class 用户信息页面
 * @time 2020/2/24
 */
public class UserInfoActivity extends SimpleActivity {

    private TimePickerView pvCustomTime;

    private OptionsPickerView pvCustomOptions;

    private ArrayList<String> cardItem = new ArrayList<>();

    @Override
    protected int getLayout() {
        return R.layout.activity_user_info;
    }

    @Override
    protected void initEventAndData() {
        cardItem.add("男");
        cardItem.add("女");
        cardItem.add("保密");
    }

    @OnClick({R.id.layout_nickname, R.id.layout_phone_no, R.id.layout_wx_no, R.id.layout_shouhuo_info, R.id.layout_sex, R.id.layout_birthday,
            R.id.layout_area})
    public void doClick(View view) {
        if (AntiShake.check(view.getId())) {    //判断是否多次点击
            return;
        }
        switch (view.getId()) {
            case R.id.layout_nickname:
                //填写昵称
                new StartActivityUtil(mContext, MyInfoSettingActivity.class).putExtra(Constants.SETTING_TYPE, 1)
                        .startActivity(true);
                break;
            case R.id.layout_phone_no:
                //填写手机号

                break;
            case R.id.layout_wx_no:
                //填写微信号

                break;
            case R.id.layout_shouhuo_info:
                //收货信息
                new StartActivityUtil(mContext, AddAddressActivity.class)
                        .startActivity(true);
                break;
            case R.id.layout_sex:
                //性别
                initCustomOptionPicker();
                break;
            case R.id.layout_birthday:
                //生日
                initTimePick();

                break;
            case R.id.layout_area:
                //地区

                break;
            default:
                break;
        }
    }

    private void initTimePick() {
        //时间选择器 ，自定义布局
        if (pvCustomTime != null) {
            pvCustomTime.show();
            return;
        }
        pvCustomTime = new TimePickerBuilder(this, new OnTimeSelectListener() {
            @Override
            public void onTimeSelect(Date date, View v) {//选中事件回调
                ToastUtil.shortShow(TimeUtils.date2String(date, "yyyy-MM-dd"));
            }
        })
                .setLayoutRes(R.layout.pickerview_custom_time, new CustomListener() {

                    @Override
                    public void customLayout(View v) {
                        TextView tvSubmit = v.findViewById(R.id.tv_finish);
                        TextView tvCancel = v.findViewById(R.id.tv_cancel);
                        tvSubmit.setOnClickListener(new View.OnClickListener() {
                            @Override
                            public void onClick(View v) {
                                pvCustomTime.returnData();
                                pvCustomTime.dismiss();
                            }
                        });
                        tvCancel.setOnClickListener(new View.OnClickListener() {
                            @Override
                            public void onClick(View v) {
                                pvCustomTime.dismiss();
                            }
                        });
                    }
                })
                .setContentTextSize(18)
                .setItemVisibleCount(5)
                .setType(new boolean[]{true, true, true, false, false, false})
                .setLabel("年", "月", "日", "时", "分", "秒")
                .setLineSpacingMultiplier(2.2f)
                .setTextXOffset(0, 0, 0, 0, 0, 0)
                .isCenterLabel(false) //是否只显示中间选中项的label文字，false则每项item全部都带有label。
                .setDividerColor(0xFFEEEEEE)
//                .setOutSideCancelable(false)
                .build();
        pvCustomTime.show();
    }


    /**
     * 条件选择器
     */
    private void initCustomOptionPicker() {

        if (pvCustomOptions != null) {
            pvCustomOptions.show();
            return;
        }

        pvCustomOptions = new OptionsPickerBuilder(this, new OnOptionsSelectListener() {
            @Override
            public void onOptionsSelect(int options1, int option2, int options3, View v) {
                ToastUtil.shortShow("当前选择：" + cardItem.get(options1));
            }
        })
                .setLayoutRes(R.layout.pickerview_custom_options, new CustomListener() {
                    @Override
                    public void customLayout(View v) {
                        TextView tvSubmit = v.findViewById(R.id.tv_finish);
                        TextView tvCancel = v.findViewById(R.id.tv_cancel);
                        tvSubmit.setOnClickListener(new View.OnClickListener() {
                            @Override
                            public void onClick(View v) {
                                pvCustomOptions.returnData();
                                pvCustomOptions.dismiss();
                            }
                        });

                        tvCancel.setOnClickListener(new View.OnClickListener() {
                            @Override
                            public void onClick(View v) {
                                pvCustomOptions.dismiss();
                            }
                        });
                    }
                })
                .setItemVisibleCount(7)
                .build();
        pvCustomOptions.setPicker(cardItem);//添加数据
        pvCustomOptions.show();
    }

    @Override
    protected int getTitleIntText() {
        return R.string.setting_grzl;
    }

    @Override
    protected void initImmersionBar() {
        super.initImmersionBar();
        ImmersionBar.with(this)
                .titleBar(mToolbar, true)
                .statusBarDarkFont(true)
                .init();
    }
}
